'----------------------------------------------
' Name: Ali Karbassi & Ben Sattler
' Date: February 15, 2007
' Description: Program 2
'              Form frmList
'----------------------------------------------
Imports UWPCS3340

Public Class frmList

   ''' <summary>
   ''' Hides current form and shows form House.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

      Me.Hide()
      frmHouse.Show()

   End Sub

   ''' <summary>
   ''' Displays the selected item in frmHouse. Hides the current form.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   btnDisplay.Click

      If lstHouses.SelectedIndex = -1 Then
         MsgBox("Please select a house to display")
      Else

         Dim id As String = CType(houseList.Item(lstHouses.SelectedIndex), House).ID()
         frmHouse.setHouseAs(id)

         Me.Hide()
         frmHouse.Show()

      End If

   End Sub

   ''' <summary>
   ''' Removes the item selected. Displays and error if nothing is selected.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   btnRemove.Click

      If lstHouses.SelectedIndex = -1 Then
         MsgBox("Please select a house to remove")
      Else

         Dim index As Integer = lstHouses.SelectedIndex
         Dim h As House = CType(houseList(index), House)

         If h.ID = frmHouse.txtID.Text Then
            frmHouse.clearForm()
         End If

         h.Dispose()
         houseList.RemoveAt(index)
         lstHouses.Items.RemoveAt(index)

         frmHouse.updateForm()

      End If

   End Sub

   ''' <summary>
   ''' Populates the list box.
   ''' </summary>
   ''' <remarks></remarks>
   Public Sub populateListBox()

      'Clears the listbox to make sure
      lstHouses.Items.Clear()

      For i As Integer = 0 To houseList.Count - 1 Step 1
         lstHouses.Items.Add(CType(houseList.Item(i), House).ID + "     " + CType(houseList.Item(i), House).Type + "     " + Format(CType(houseList.Item(i), House).Price, "currency"))
      Next

      frmHouse.updateForm()

   End Sub

End Class